import request from '../request/index'
import axios from "axios";

//定义登录请求方法
export function findAllTaskGroup(data){
    return request({
        url: '/DeliveryApi/delivery/findAllTaskGroup',
        method: 'post',
        data: data  //省略结构data: data
    })
}

// 获取任务包列表
export function getTaskPackages(queryPage) {
    return request({
        url: '/DeliveryApi/delivery/task-packages',
        method: 'post',
        data: queryPage
    })
}

/**
 * 获取任务包统计数据
 * @returns {Promise<axios.AxiosResponse<any>>}
 */
export function getTaskPackageStats() {
    return request({
        url: '/DeliveryApi/delivery/task-package-stats',
        method: 'get',
    })
}

// 获取任务包详情
export function getTaskPackageDetail(packageId) {
    return request({
        url: `/DeliveryApi/delivery/task-package`,
        method: 'get',
        params: { PackageId: packageId }
    })
}

// 接受任务包
export function acceptTaskPackage(packageId) {
    return request({
        url: '/DeliveryApi/delivery/acceptTaskPackage',
        method: 'post',
        data: { packageId }
    })
}

// 开始配送任务包
export function startTaskPackageDelivery(packageId) {
    return request({
        url: '/DeliveryApi/delivery/startTaskPackageDelivery',
        method: 'post',
        data: { packageId }
    })
}

// 完成任务包配送
export function completeTaskPackage(packageId) {
    return request({
        url: '/DeliveryApi/delivery/completeByPackage',
        method: 'post',
        params: { packageId }
    })
}

// 扫码取货
export function scanPackage(orderNumber, scanCode) {
    return request({
        url: '/DeliveryApi/delivery/scanPackage',
        method: 'post',
        data: { orderNumber, scanCode }
    })
}

// 签收订单
export function signOrder(orderNumber) {
    return request({
        url: '/DeliveryApi/delivery/signOrder',
        method: 'post',
        data: { orderNumber }
    })
}

// 上报异常接口
export function reportException(data) {
  return request({
    url: '/DeliveryApi/delivery/exception',
    method: 'post',
    data
  })
}

// 获取配送员通知列表
export function getDeliveryNotifications() {
    return request({
        url: '/DeliveryApi/delivery/getNotifications',
        method: 'get'
    })
}
// 标记单条消息为已读
export function markNotificationAsRead(id) {
    return axios.post('/DeliveryApi/delivery/read', { id })
  }
  
  // 全部标为已读
  export function markAllNotificationsAsRead() {
    return axios.post('/DeliveryApi/delivery/readAll')
  }
// 获取待接单任务包列表
export function getPendingTaskPackages() {
    return request({
        url: '/DeliveryApi/delivery/getPendingTaskPackages',
        method: 'get'
    })
}

// 上传异常图片接口
export function uploadExceptionImage(formData) {
  return request({
    url: '/DeliveryApi/delivery/uploadImage',
    method: 'post',
    data: formData,
    headers: { 'Content-Type': 'multipart/form-data' }
  })
}

// 获取异常单列表（分页+筛选）
export function fetchExceptionList(data) {
  return request({
    url: '/DeliveryApi/delivery/list',
    method: 'post',
    data
  })
}

// 获取异常详情
export function fetchExceptionDetail(id) {
  return request({
    url: '/DeliveryApi/delivery/detail',
    method: 'get',
    params: { id }
  })
}

// 新建异常单
export function createException(data) {
  return request({
    url: '/DeliveryApi/exception/create',
    method: 'post',
    data
  })
}

// 处理异常
export function processException(data) {
  return request({
    url: '/DeliveryApi/exception/process',
    method: 'post',
    data
  })
}

// 发送异常留言
export function sendExceptionMessage(data) {
  return request({
    url: '/DeliveryApi/exception/message',
    method: 'post',
    data
  })
}

// 取消配送，将任务包状态变为待配送
export function cancelTaskPackage(packageId) {
  return request({
    url: '/DeliveryApi/delivery/cancel', // 你后端的取消接口路径
    method: 'post',
    data: { packageId }
  })
}

//异常类型
export function getEXTypeList(data) {
    return request({
      url: '/DeliveryApi/delivery/extypelist', // 你后端的取消接口路径
      method: 'get',
      data:data
    })
  }
  //严重程度
export function getEXSeverity(data) {
    return request({
      url: '/DeliveryApi/delivery/exseverity', // 你后端的取消接口路径
      method: 'get',
      data:data
    })
  }

// 确认揽收任务包
export function collectPackage(packageId) {
  return request({
    url: `/DeliveryApi/delivery/collect/${packageId}`,
    method: 'post'
  })
}

// 查询某快递员下有未揽收订单的任务包列表
export function getUncollectedPackagesByDeliveryman(deliverymanId) {
  return request({
    url: `/DeliveryApi/delivery/package/uncollectedList?deliverymanId=${deliverymanId}`,
    method: 'get'
  })
}

// 获取配送员个人信息
export function getDeliverymanInfo() {
  return request({
    url: '/DeliveryApi/delivery/deliveryman',
    method: 'get'
  })
}